package severlet;

import bean.Guarantee;
import dao.GuaranteeDao;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "StudentGuaranteeSbmitServlet", value = "/StudentGuaranteeSbmitServlet")
public class StudentGuaranteeSbmitServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");

        String dormitoryid = request.getParameter("dormitoryid");
        String studentname = request.getParameter("studentname");
        String goodsname = request.getParameter("goodsname");
        String reason = request.getParameter("reason");
        String phoneid = request.getParameter("phoneid");
        if (dormitoryid == "" || studentname == "" || goodsname == "" || reason == "" || phoneid == "") {
            request.getRequestDispatcher("FanHui.jsp").forward(request, response);
        } else {
            //封装对象
            Guarantee guarantee = new Guarantee();
            guarantee.setDormitoryid(dormitoryid);
            guarantee.setStudentname(studentname);
            guarantee.setGoodsname(goodsname);
            guarantee.setReason(reason);
            guarantee.setPhoneid(phoneid);

            //调用数据库
            GuaranteeDao guaranteeDao = new GuaranteeDao();
            //        提交
            guaranteeDao.submit(guarantee);

            request.getRequestDispatcher("/StudentGuaranteeServlet").forward(request, response);
        }
    }
}